import os
import shutil
import re

path = '/Users/jiangce/Desktop/标记'
xmls_path = '/Users/jiangce/Desktop/Annotations'
images_path = '/Users/jiangce/Desktop/JPEGImages'
jdg_xml = re.compile('xml')

def copyfiles(path, images_path, xmls_path):
    if not os.path.exists(xmls_path):
        os.mkdir(xmls_path)
    if not os.path.exists(images_path):
        os.mkdir(images_path)


    dirs = os.listdir(path)
    for dir in dirs:
        if not dir.startswith('.'):
            if jdg_xml.search(dir):
                xml_path = os.path.join(path, dir)
                files = os.listdir(xml_path)
                for file in files:
                    shutil.copy(os.path.join(xml_path, file),os.path.join(xmls_path, file))
            else:
                image_path = os.path.join(path, dir)
                files = os.listdir(image_path)
                for file in files:
                    shutil.copy(os.path.join(image_path, file),os.path.join(images_path, file))
def judgeTwodir(dir1_path, dir2_path):
    dirs1 = os.listdir(dir1_path)
    dirs2 = os.listdir(dir2_path)
    for dir1 in dirs1:
        dir1_name = dir1.split('.')[0]
        dir2 = dir1_name + '.xml'
        if not dir2 in dirs2:
            print(dir1)
def getTrain(path):
    with open('/Users/jiangce/Desktop/train.txt', 'w') as f:
        files = os.listdir(path)
        for file in files:
            f.write(file.split('.')[0])
            f.write('\n')
getTrain(images_path)